package StudyCode.summary.myfile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GeiFileAttributeByNIO {
	public static void main(String[] argv) throws Exception {
		File file = new File("E:\\迅雷下载\\test1.txt");
		System.out.println(getFileAttributes(file));
	}

	private static BasicFileAttributes getFileAttributes(File file) throws IOException {
		return getFileAttributes(file.toPath());
	}

	private static BasicFileAttributes getFileAttributes(Path path) throws IOException {
		if (path.getFileSystem().supportedFileAttributeViews().contains("posix")) {

			try {
				return Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
			} catch (UnsupportedOperationException ignore) {
				ignore.printStackTrace();
			}
		}
		return Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
	}
}
